<?php
include_once '../connexpdo.php';
include_once ('../class/config.inc.php');

$vretour = array ();
if (! isset ( $_POST ['Tech'] ) && ! isset ( $_POST ['Mois'] )) {
	$query = "SELECT * FROM appels ";
	$return = $connexion->query ( $query );
	while ( $row = $return->fetch () ) {
		
		// $data[]=array_map('utf8_array', array("nature"=>$row['nature']));
		$data [] = array (
				"id" => $row ['idAppels'],
				"duree" => $row ['duree'],
				"date" => $row ['dateDebut'] 
		);
		array_push ( $vretour, $data );
	}
	
	echo json_encode ( $data );
} else {
	if (isset ( $_POST ['Tech'] )) {
		$query = 'SELECT * FROM appels WHERE idtech ="' . $_POST ['Tech'] . '";';
		$return = $connexion->query ( $query );
		while ( $row = $return->fetch () ) {
			
			// $data[]=array_map('utf8_array', array("nature"=>$row['nature']));
			$data [] = array (
					"id" => $row ['idAppels'],
					"duree" => utf8_array ( $row ['duree'] ),
					"date" => utf8_array ( $row ['dateDebut'] ) 
			);
			array_push ( $vretour, $data );
		}
		
		echo json_encode ( $data );
	}
	if (isset ( $_POST ['Mois'] )) {
		
		$query = 'SELECT * FROM appels WHERE MONTH(dateDebut) =' . $_POST ['Mois'] . ';';
		$return = $connexion->query ( $query );
		while ( $row = $return->fetch () ) {
			
			// $data[]=array_map('utf8_array', array("nature"=>$row['nature']));
			$data [] = array (
					"id" => $row ['idAppels'],
					"duree" => utf8_array ( $row ['duree'] ),
					"date" => utf8_array ( $row ['dateDebut'] ) 
			);
			array_push ( $vretour, $data );
		}
		
		echo json_encode ( $data );
	}
}
function utf8_array($data) {
	return utf8_encode ( $data );
}
?>